﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightingReflectionApp
{
    public static class LampEfficiencyCalculator
    {
        private static readonly Dictionary<int, double> TemperatureToEfficiency = new Dictionary<int, double>
        {
            { 2000, 80 },
            { 2500, 85 },
            { 3000, 90 },
            { 3500, 95 },
            { 4000, 100 },
            { 4500, 105 },
            { 5000, 110 },
            { 5500, 105 },
            { 6000, 100 },
            { 6500, 95 }
        };

        public static double GetEfficiency(int colorTemperature)
        {

            if (TemperatureToEfficiency.ContainsKey(colorTemperature))
            {
                return TemperatureToEfficiency[colorTemperature];
            }

            // Поиск ближайших точек

            // Проверка граничных условий
            if (colorTemperature <= 2000) return 80;
            if (colorTemperature >= 6500) return 95;

            // Поиск ближайших точек
            int lowerKey = 2000;
            int upperKey = 6500;

            foreach (var key in TemperatureToEfficiency.Keys)
            {
                if (key <= colorTemperature && key > lowerKey)
                    lowerKey = key;
                if (key >= colorTemperature && key < upperKey)
                    upperKey = key;
            }

            // Линейная интерполяция
            double lowerValue = TemperatureToEfficiency[lowerKey];
            double upperValue = TemperatureToEfficiency[upperKey];

            return lowerValue + (upperValue - lowerValue) * (colorTemperature - lowerKey) / (upperKey - lowerKey);
        }
    }
}
